package cn.com.bluemoon.daps.api.model;


import cn.com.bluemoon.daps.api.model.factory.RemoteDataModelServiceFallbackFactory;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiModel;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.model.dto.ModelInfos;
import cn.com.bluemoon.daps.model.entity.DapDataModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author Jarod.Kong
 */
@FeignClient(value = DapsApiModel.SERVICE, fallbackFactory = RemoteDataModelServiceFallbackFactory.class)
@RequestMapping(DapsApiModel.BASE_URI + DapsApiModel.API_MODEL)
@ApiIgnore
public interface RemoteDataModelService {

    @GetMapping("/{id}")
    ResultBean<DapDataModel> getById(@PathVariable("id") String id);

    @GetMapping("/get/{systemId}")
    @ApiOperation(value = "通过系统id获取模型列表")
    List<DapDataModel> findBySystemId(@PathVariable("systemId") String systemId);

    @GetMapping("/model/{sysId}")
    @ApiOperation(value = "某个系统下已经被其他模型引用的数据源")
    ResultBean<List<DapDataModel>> getModelList(@PathVariable("sysId") String sysId);

    @GetMapping("/isUse")
    @ApiOperation(value = "查询系统是否被模型引用")
    ResultBean<List<DapDataModel>> getModels(@RequestParam("sysId")
                                             @ApiParam("模型id") String sysId);

    @PostMapping("batch/List")
    @ApiOperation(value = "查询系统是否被模型引用")
    ResultBean<List<DapDataModel>> getBatchModel(@RequestBody List<String> systemIds);


    @GetMapping("/queryModelInfos")
    @ApiOperation(value = "并行获取模型下的表、字段、索引、分区信息")
    ResultBean<ModelInfos> queryModelInfosByModelAndNewest(@RequestParam("modelId") String modelId, @RequestParam(value = "newest") Boolean newest);

    /**
     * 获取模型表信息
     *
     * @param modelId  模型id
     * @param newest   true 模型中最新表数据 false模型中最新历史版本数据
     * @param tableIds null获取模型所有表、空返回空、不为null且不为空则返回指定的表id信息
     */
    @GetMapping("/queryModelInfosV2")
    @ApiOperation(value = "并行获取模型下的表、字段、索引、分区信息")
    ResultBean<ModelInfos> queryModelInfosByModelAndNewestAndTableIds(@RequestParam("modelId") String modelId, @RequestParam(value = "newest") Boolean newest, @RequestParam(value = "tableIds", required = false) List<String> tableIds);

    @GetMapping("/matchName")
    @ApiOperation(value = "模糊获取模型列表")
    ResultBean<List<DapDataModel>> findAllOrFindLikeName(@RequestParam("modelName") String name);

    @GetMapping("/get/bizLine/model")
    @ApiOperation(value = "查询业务线是否被模型引用")
    public ResultBean<Boolean> getBizLineModel(@RequestParam("bizId") Integer bizId);

}
